package com.aiq.service.impl;

import com.aiq.constants.ConstantCode;
import com.aiq.dao.AdminMapper;
import com.aiq.exceptions.MyBaseException;
import com.aiq.pojo.Admin;
import com.aiq.service.AdminService;
import com.aiq.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName: AdminServiceImpl
 * @Description: 实现管理员业务逻辑
 * @Author: vie0134
 * @Date: 2021-01-11 15:24
 * @Version: 1.0
 **/
@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public R verifyPassword(String name, String password) {
        if (name == null && password == null) {
            throw new MyBaseException("没有传递信息", ConstantCode.DATA_NOT_TRANSFER);
        }
        try {
            Admin admin = adminMapper.verifyPassword(name, password);
//            assert name != null;
            if (name.equals(admin.getName()) && password.equals(admin.getPassword())) {
                return R.setSuccess(admin);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        throw new MyBaseException("查询失败", ConstantCode.ERROR);
    }
}
